﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FairyGUI;

namespace Model
{
    /// <summary>
    /// 单个UI界面逻辑接口
    /// </summary>
    public abstract class UIView
    {
        public GComponent MainUI;
        public abstract string PackageName { get;}
        public abstract string ViewName { get; }
        public virtual void Enter()
        {
            UIViewComponent Uvc = GameRoot.Scene.GetComponent<UIViewComponent>();
            if (MainUI == null)
            {
                if (Uvc.loadedPackage.Contains(PackageName))
                {
                    MainUI = UIPackage.CreateObject(PackageName, ViewName).asCom;
                    MainUI.SetSize(GRoot.inst.width, GRoot.inst.height);
                    MainUI.AddRelation(GRoot.inst, RelationType.Size);
                    MainUI.fairyBatching = true;
                    GRoot.inst.AddChild(MainUI);
                    Create();
                }
            }
            MainUI.visible = true;

        }
        public abstract void Create();
        public abstract void OnEnter();

        public virtual void Leave()
        {
            MainUI.visible = false;
        }
    }
}
